﻿/***********************************************
 * 
 *      创建：lito
 *      
 *      时间：2016-01-28
 * 
 *      描述：日志文件，系统错误日志文件
 * 
 * *********************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NF_Base
{
    public class ErroLog
    {
        /// <summary>
        /// 输出错误日志
        /// </summary>
        /// <param name="ex">异常对象</param>
        public static void SysLog(Exception ex)
        {
            if (!System.IO.Directory.Exists(Application.StartupPath + "\\Log\\"))
                System.IO.Directory.CreateDirectory(Application.StartupPath + "\\Log\\");

            string FileName = Application.StartupPath + "\\Log\\Erro" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
            string LogMeg = "异常时间：" + DateTime.Now + "\r\n";
            LogMeg += "异常消息:" + ex.Message + "\r\n";
            LogMeg += "异常对象：" + ex.Source + "\r\n";
            LogMeg += "调用堆栈：" + ex.StackTrace + "\r\n";
            LogMeg += "调用对象：" + ex.InnerException + "\r\n";
            LogMeg += "触发方法：" + ex.TargetSite + "\r\n\r\n\r\n";
            System.IO.File.AppendAllText(FileName, LogMeg);

        }

    }
}
